using System.Data.SqlClient;

namespace Library_management_system
{
    public static class DatabaseConfig
    {
        // 数据库连接字符串配置
        // 请根据你的实际数据库信息修改以下参数
        public static readonly string ConnectionString = "Data Source=MOFUDONG;Initial Catalog=Library_management_system;Integrated Security=true;TrustServerCertificate=true";

        // 如果使用SQL Server身份验证，请使用以下格式：
        // "Data Source=localhost;" +
        // "Initial Catalog=LibraryDB;" +
        // "User ID=your_username;" +
        // "Password=your_password;" +
        // "TrustServerCertificate=true";

        // 系统配置参数
        public static readonly int MaxBorrowCount = 5;        // 最大借阅数量
        public static readonly decimal DailyFineRate = 0.5m;  // 每日罚款金额
        public static readonly int DefaultBorrowDays = 14;    // 默认借阅天数

        public static SqlConnection GetConnection()
        {
            return new SqlConnection(ConnectionString);
        }

        public static void TestConnection()
        {
            try
            {
                using (SqlConnection connection = GetConnection())
                {
                    connection.Open();
                    Console.WriteLine("Database connection successful!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Error connecting to database: {ex.Message}");
                throw;
            }
        }
    }
}